<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增角色')" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form class="form-horizontal m" id="form-role-add">
		<div class="form-group">
			<label class="col-sm-3 control-label">任务标题：</label>
			<div class="col-sm-9">
				<input type="text" name="title" style="width: 200px" class="form-control" placeholder="请输入文本">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label">延期到：</label>
			<div class="col-sm-9">
				<input type="text" name="endDate" class="form-control" style="width: 200px" value="">
			</div>
		</div>


		<div class="form-group">
			<label class="col-sm-3 control-label">申请人：</label>
			<div class="col-sm-9">
				<input type="text" name="aname" style="width: 200px" class="form-control" placeholder="请输入文本">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label" >上级：</label>
			<div class="col-sm-9" style="width: 200px">

				<select class="form-control" id="cname" name="cname">
					<option value="">请选择上级：</option>
					<option value="总经理">总经理</option>
					<option value="项目经理">项目经理</option>
					<option value="组长">组长</option>
				</select>
			</div>
		</div>

		<div class="form-group">
			<label class="col-sm-3 control-label">申请原因：</label>
			<div class="col-sm-9">
				<input type="text" name="cause" class="form-control" placeholder="请输入文本">
			</div>
		</div>

	</form>  
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: ztree-js" />
<script type="text/javascript">

	/*$(function () {
		$("#ename").change(function () {

		})
	})*/

	$(function() {
		var url = ctx + "system/menu/roleMenuTreeData";
		var options = {
			id: "menuTrees",
			url: url,
			check: { enable: true },
			expandLevel: 0
		};
		$.tree.init(options);
	});
	$("#form-role-add").validate({
		rules:{
			onkeyup: false,
			roleName:{
				remote: {
					url: ctx + "system/role/checkRoleNameUnique",
					type: "post",
					dataType: "json",
					data: {
						"roleName" : function() {
							return $.common.trim($("#roleName").val());
						}
					},
					dataFilter: function(data, type) {
						return $.validate.unique(data);
					}
				}
			},
			roleKey:{
				remote: {
					url: ctx + "system/role/checkRoleKeyUnique",
					type: "post",
					dataType: "json",
					data: {
						"roleKey" : function() {
							return $.common.trim($("#roleKey").val());
						}
					},
					dataFilter: function(data, type) {
						return $.validate.unique(data);
					}
				}
			},
			roleSort:{
				digits:true
			},
		},
		messages: {
			"roleName": {
				remote: "角色名称已经存在"
			},
			"roleKey": {
				remote: "角色权限已经存在"
			}
		},
		focusCleanup: true
	});

	function submitHandler() {
		if ($.validate.form()) {
			add();
		}
	}

	function add() {
		var title = $("input[name='title']").val();
		var endDate = $("input[name='endDate']").val();
		var cname = $("#cname").val();
		var aname = $("input[name='aname']").val();
		var cause = $("input[name='cause']").val();
		$.ajax({
			cache : true,
			type : "POST",
			url : ctx + "cms/taskdelayask/addSave",
			data : {
				"title": title,
				"endDate": endDate,
				"cname": cname,
				"aname": aname,
				"cause": cause,
			},
			async : false,
			error : function(request) {
				$.modal.alertError("12456");
			},
			success : function(data) {
				$.operate.successCallback(data);
			}
		});
	}
</script>
</body>
</html>



